

package TransportesMarroquin;

import com.mysql.jdbc.Connection;

import java.awt.event.ActionEvent; 
import java.awt.event.KeyEvent; 
import javax.sound.sampled.Clip; 
import javax.swing.JButton; 
import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.JPanel; 
import javax.swing.JTextField;
import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.Statement;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import java.awt.Color;
import java.awt.Toolkit;
import java.io.File;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.sampled.AudioSystem;
import javax.swing.JOptionPane;


public class LlantasFurgon extends javax.swing.JFrame {
javax.sound.sampled.Clip sonido;
  // areglo donde guardare todos los id de los numeros de las llantas 

  int[] num = new int[8]; // arreglo de numeros
   int resultado;
   int codpaquete;
   boolean error = false;
   boolean completo = false;
   int codfur=0;  // el codigo qee trai de furgon

   Limitador limddd = new Limitador(11);
   Limitador limddi = new Limitador(11);
   Limitador limdid = new Limitador(11);
   Limitador limdii = new Limitador(11);
   Limitador limtdd = new Limitador(11);
   Limitador limtdi = new Limitador(11);
   Limitador limtid = new Limitador(11);
   Limitador limtii = new Limitador(11);

    public LlantasFurgon(int cod) {  // constructor 
        this.codfur=cod;  // es igual al codigo qee trai del furgon 
        initComponents();
     ddd.setDocument(limddd);
     ddi.setDocument(limddi);
     did.setDocument(limdid);
     dii.setDocument(limdii);
     tdd.setDocument(limtdd);
     tdi.setDocument(limtdi);
     tid.setDocument(limtid);
     tii.setDocument(limtii);
    }

    private LlantasFurgon() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel11 = new javax.swing.JLabel();
        tdd = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        tdi = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        tid = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        dii = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        did = new javax.swing.JTextField();
        ddi = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        ddd = new javax.swing.JTextField();
        tii = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/ImagenLlanta.png"))); // NOI18N

        tdd.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tddKeyTyped(evt);
            }
        });

        jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/ImagenLlanta.png"))); // NOI18N

        tdi.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tdiKeyTyped(evt);
            }
        });

        jLabel14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/ImagenLlanta.png"))); // NOI18N

        tid.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tidKeyTyped(evt);
            }
        });

        jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/ImagenLlanta.png"))); // NOI18N

        jLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/ImagenLlanta.png"))); // NOI18N

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/ImagenLlanta.png"))); // NOI18N

        dii.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                diiKeyTyped(evt);
            }
        });

        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/ImagenLlanta.png"))); // NOI18N

        did.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                didKeyTyped(evt);
            }
        });

        ddi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ddiActionPerformed(evt);
            }
        });
        ddi.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                ddiKeyTyped(evt);
            }
        });

        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/ImagenLlanta.png"))); // NOI18N

        ddd.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                dddKeyTyped(evt);
            }
        });

        tii.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                tiiKeyTyped(evt);
            }
        });

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/aceptar.png"))); // NOI18N
        jButton1.setText("Ingresar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/cancelar.png"))); // NOI18N
        jButton3.setText("Cancelar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/regresar.png"))); // NOI18N
        jButton2.setText("Regresar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(143, 0, 0));

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel13.setForeground(new java.awt.Color(255, 255, 255));
        jLabel13.setText("Nuevo Furgon                           - LLantas -");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 360, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(79, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel13)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(tii)
                            .addComponent(dii, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel7))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel11)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel14)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(tid)
                            .addComponent(did, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(55, 55, 55))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton2)
                        .addGap(94, 94, 94)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(35, 35, 35)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(tdi)
                            .addComponent(ddi, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel10)
                            .addComponent(jLabel4))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel12))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(ddd, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tdd, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton3))))
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton1, jButton2, jButton3});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 184, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(dii, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5)
                            .addComponent(jLabel7))
                        .addGap(49, 49, 49)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel11)
                            .addComponent(jLabel14)
                            .addComponent(tii, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(tid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(did, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(102, 102, 102))
                    .addComponent(tdi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(ddi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel4))
                                .addGap(49, 49, 49)
                                .addComponent(jLabel10))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(ddd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel6))
                                .addGap(49, 49, 49)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel12, javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(tdd, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(3, 3, 3)))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jButton1, jButton2, jButton3});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
error=false;

        IngresarLlantas();

if (error==false){
     LlenarPacketeN();
}
if(completo==true){
            IngresarPaqueteAFurgon();
            Furgones.nf.dispose();
            dispose();
            Furgones va;
       
            va = new Furgones();
            va.setVisible(true);
             va.setBounds(114, 107, Toolkit.getDefaultToolkit().getScreenSize().width-114, Toolkit.getDefaultToolkit().getScreenSize().height-107);
      
} // fin del if de completo



    }//GEN-LAST:event_jButton1ActionPerformed
public void IngresarLlantas (){

        try {
            resultado = 0;
            MysqlDataSource dataSource = new MysqlDataSource();
            dataSource.setUser("root");
            dataSource.setPassword("");
            dataSource.setDatabaseName("practicasp8");
            dataSource.setServerName("localhost");
            Connection conexion = (Connection) dataSource.getConnection();
            Statement instruccion;

            instruccion = (Statement) conexion.createStatement();
          
            // LLANTA UNO

           
                  try {
                num[0] = Integer.parseInt(dii.getText()); // en el arreglo de la posicion uno ingrese el valor de la caja de dii qee seria la
                // llanta derecha izquiera exterior.
            } catch (Exception e) {
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta delantera izquierda externa, no es un valor númerico ");
            }
                if(error==false){
            try{
                 instruccion.executeUpdate("insert into llanta (idnumeconomico,tipo_vehiculo,codigo_vehiculo,posicion) values('" + num[0] + "','Furgon','"+codfur+"','Llanta delantera izquierda externa')",Statement.RETURN_GENERATED_KEYS); // me sirve para obter el id de llanta uno
            }catch (Exception e ){
                error=true;
                GeneracionError();
                dii.setText(""+"Error");
                dii.setBackground(Color.red);
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta delantera izquierda externa ''"+num[0] +"'' número economico ya existente"+e);
            }
          
            }
          
          
            // LLANTA DOS

           
                 try {

                num[1] = Integer.parseInt(did.getText());
            } catch (Exception e) {
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta delantera izquierda interior, no es un valor númerico ");
            }

                 // este try borra todos los datos anteriormente ya ingresados para evitar errore
                 // asi como tambien para que el usuario localice el error
             if(error==false){    // este if verifica continuidad del error si hay error anteriormente no ingresa nada :D
                 try{
                instruccion.executeUpdate("insert into llanta (idnumeconomico,tipo_vehiculo,codigo_vehiculo,posicion) values ('" + num[1] + "','Furgon','"+codfur+"','Llanta delantera izquierda interior')",Statement.RETURN_GENERATED_KEYS);
                 }catch (Exception e ){
                error=true;
                GeneracionError();
                did.setText(""+"Error");
                did.setBackground(Color.red);
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta delantera izquierda interna ''"+num[1] +"'' número economico ya existente");
            }
           
            }
           
            
            //LLANTA TRES

            if (error==false){
                try {
                num[2] = Integer.parseInt(ddi.getText());
            } catch (Exception e) {
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta delantera derecha interna, no es un valor númerico");
            }
             try{
                instruccion.executeUpdate("insert into llanta (idnumeconomico,tipo_vehiculo,codigo_vehiculo,posicion) values ('" + num[2] + "','Furgon','"+codfur+"','Llanta delantera derecha interna')",Statement.RETURN_GENERATED_KEYS);
                 }catch (Exception e ){
                error=true;
                GeneracionError();
                ddi.setText(""+"Error");
                ddi.setBackground(Color.red);
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta delantera derecha interna ''"+num[2] +"'' número economico ya existente");
            }

            }
        
            // LLANTA CUATRO

            if (error==false){
                 try {
                num[3] = Integer.parseInt(ddd.getText());
            } catch (Exception e) {
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta delantera derecha externa, no es un valor númerico");
            }
             try{
                instruccion.executeUpdate("insert into llanta (idnumeconomico,tipo_vehiculo,codigo_vehiculo,posicion) values ('" + num[3] + "','Furgon','"+codfur+"','Llanta delantera derecha externa')",Statement.RETURN_GENERATED_KEYS);
                 }catch (Exception e ){
                error=true;
                GeneracionError();
                ddd.setText(""+"Error");
                ddd.setBackground(Color.red);
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta delantera derecha externa ''"+num[3] +"'' número economico ya existente");
            }
            }
           
            //LLANTA CINCO
            if(error==false){

                try {
                num[4] = Integer.parseInt(tii.getText());
            } catch (Exception e) {
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta trasera izquierda externa, no es un valor númerico");
            }
            try{
                instruccion.executeUpdate("insert into llanta (idnumeconomico,tipo_vehiculo,codigo_vehiculo,posicion) values ('" + num[4] + "','Furgon','"+codfur+"','Llanta trasera izquierda externa')",Statement.RETURN_GENERATED_KEYS);
                 }catch (Exception e ){
                error=true;
                GeneracionError();
                tii.setText(""+"Error");
                tii.setBackground(Color.red);
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta trasera izquierda externa ''"+num[4] +"'' número economico ya existente");
            }
            }
            
           
            //LANTA SEIS

            if(error == false){
                  try {
                num[5] = Integer.parseInt(tid.getText());
            } catch (Exception e) {
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta trasera izquierda interna, no es un valor númerico");
            }
           try{
                instruccion.executeUpdate("insert into llanta (idnumeconomico,tipo_vehiculo,codigo_vehiculo,posicion) values ('" + num[5] + "','Furgon','"+codfur+"','Llanta trasera izquierda interna')",Statement.RETURN_GENERATED_KEYS);
                 }catch (Exception e ){
                error=true;
                GeneracionError();
                tid.setText(""+"Error");
                tid.setBackground(Color.red);
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta trasera izquierda interna ''"+num[5] +"'' número economico ya existente");
            }
            }
          
          
           
            //LLNATA SIETE
            if(error==false){
                 try {
                num[6] = Integer.parseInt(tdi.getText());
            } catch (Exception e) {
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta trasera derecha interna, no es un valor númerico");
            }
            try{
                instruccion.executeUpdate("insert into llanta (idnumeconomico,tipo_vehiculo,codigo_vehiculo,posicion) values ('" + num[6] + "','Furgon','"+codfur+"','Llanta trasera derecha interna')",Statement.RETURN_GENERATED_KEYS);
                 }catch (Exception e ){
                error=true;
                GeneracionError();
                tdi.setText(""+"Error");
                tdi.setBackground(Color.red);
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta trasera derecha interna ''"+num[6] +"'' número economico ya existente");
            }
            }
           
           
            //LLANTA OCHO
            if(error==false){
                try {
                num[7] = Integer.parseInt(tdd.getText());
            } catch (Exception e) {
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta trasera derecha externa, no es un valor númerico");
            }
           try{
                instruccion.executeUpdate("insert into llanta (idnumeconomico,tipo_vehiculo,codigo_vehiculo,posicion) values ('" + num[7] + "','Furgon','"+codfur+"','Llanta trasera derecha externa')",Statement.RETURN_GENERATED_KEYS);
                
                      
           }catch (Exception e ){
                error=true;
                GeneracionError();
                tdd.setText(""+"Error");
                tdd.setBackground(Color.red);
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en la llanta trasera derecha externa ''"+num[7] +"'' número economico ya existente");
            }
            }
           
           
         
        } catch (SQLException ex) {
            Logger.getLogger(LlantasFurgon.class.getName()).log(Level.SEVERE, null, ex);
        }

   }

  public void GeneracionError (){
        try {
            MysqlDataSource dataSource = new MysqlDataSource();
            dataSource.setUser("root");
            dataSource.setPassword("");
            dataSource.setDatabaseName("practicasp8");
            dataSource.setServerName("localhost");
            Connection conexion = (Connection) dataSource.getConnection();
            Statement instruccion;

            instruccion = (Statement) conexion.createStatement();
            for(int i=0; i!=8;i++){
               instruccion.executeUpdate("DELETE from llanta where idnumeconomico = "+num[i] +"AND codigo_vehiculo ="+codfur+"AND tipo_vehiculo LIKE 'Furgon'");
               
            }
            conexion.close();
            instruccion.close();
        } catch (SQLException ex) {
            Logger.getLogger(LlantasFurgon.class.getName()).log(Level.SEVERE, null, ex);
           
        }
  }

   public void LlenarPacketeN (){
     
       {

     try {
           

            MysqlDataSource dataSource = new MysqlDataSource();
            dataSource.setUser("root");
            dataSource.setPassword("");
            dataSource.setDatabaseName("practicasp8");
            dataSource.setServerName("localhost");
             // coneccion
            Connection conexion = (Connection) dataSource.getConnection();
           
            PreparedStatement ps = null;
            ResultSet rs; // para guardar un codigo.

            ps = (PreparedStatement) conexion.prepareStatement("insert into paquetefurgon (dii,did,ddi,ddd,tii,tid,tdi,tdd) values (?,?,?,?,?,?,?,?)",PreparedStatement.RETURN_GENERATED_KEYS);

 //LLANTA UNO
            try {
                 ps.setInt(1,num[0]);
            }catch(Exception e){
                   JOptionPane.showMessageDialog(rootPane, "Dato erroneo Revisar Manual  ");

           } // fin del catch

  // LLANTA DOS



            try {
                 ps.setInt(2,num[1]);
            }catch(Exception e){
                   JOptionPane.showMessageDialog(rootPane, "Dato erroneo Revisar Manual  ");

           } // fin del catch

//LANTA TRES

            try {
                 ps.setInt(3,num[2]);
            }catch(Exception e){
                   JOptionPane.showMessageDialog(rootPane, "Dato erroneo Revisar Manual  ");

           } // fin del catch
 // LLANTA CUATRO


            try {
                 ps.setInt(4,num[3]);
            }catch(Exception e){
                   JOptionPane.showMessageDialog(rootPane, "Dato erroneo Revisar Manual  ");

           } // fin del catch
 //LLANTA CINCO

            try {
                 ps.setInt(5,num[4]);
            }catch(Exception e){
                   JOptionPane.showMessageDialog(rootPane, "Dato erroneo Revisar Manual  ");

           } // fin del catch
 //LANTA SEIS


            try {
                 ps.setInt(6,num[5]);
            }catch(Exception e){
                   JOptionPane.showMessageDialog(rootPane, "Dato erroneo Revisar Manual  ");

           } // fin del catch
   //LLNATA SIETE


            try {
               ps.setInt(7,num[6]);
            }catch(Exception e){
                   JOptionPane.showMessageDialog(rootPane, "Dato erroneo Revisar Manual  ");

           } // fin del catch
 //LLANTA OCHO


            try {
                 ps.setInt(8,num[7]);
            }catch(Exception e){
                   JOptionPane.showMessageDialog(rootPane, "Dato erroneo Revisar Manual  ");

           } // fin del catch

             resultado = ps.executeUpdate();

            rs = ps.getGeneratedKeys();
            while (rs.next()) {
                codpaquete = rs.getInt(1);
                
                }

// sonido


try
{
  sonido = null;
  sonido=AudioSystem.getClip();
  sonido.open(AudioSystem.getAudioInputStream(new File(System.getProperty ("user.dir")+"\\src\\SonidosPractica\\Correcto2.wav")));
  sonido.start();




}catch(Exception e)
  {System.out.println(""+e);} // fin

            JOptionPane.showMessageDialog(rootPane, "Dato ingresado exitosamente");

               conexion.close(); // cierro la conexion
               ps.close();

             }catch(SQLException e){

           
           } // fin del catch
      completo=true; // se a completado el ingreso de llanta
       }
   }

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
       dispose();
       Furgones.nf.dispose();
       Error.Mysql("delete from furgon where idfurgon="+codfur);
       Furgones va;
       
            va = new Furgones();
            va.setVisible(true);
             va.setBounds(114, 107, Toolkit.getDefaultToolkit().getScreenSize().width-114, Toolkit.getDefaultToolkit().getScreenSize().height-107);
  // borrar los datos anteriormente       
       
    }//GEN-LAST:event_jButton3ActionPerformed

    public void  IngresarPaqueteAFurgon (){
        try {
            MysqlDataSource dataSource = new MysqlDataSource();
               dataSource.setUser("root");
               dataSource.setPassword("");
               dataSource.setDatabaseName("practicasp8");
               dataSource.setServerName("localhost");
               Connection conexion = (Connection) dataSource.getConnection();
               Statement instruccion;
               
               instruccion=(Statement) conexion.createStatement();
               instruccion.executeUpdate("update furgon set idpaquetefurgon='"+ codpaquete+"' where idfurgon="+codfur);
        } catch (SQLException ex) {
            Logger.getLogger(LlantasFurgon.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    private void ddiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ddiActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ddiActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        NuevoFurgon.va.dispose();
        Furgones.nf.show();
        Error.Mysql("DELETE from furgon where idfurgon = "+NuevoFurgon.enviarcod);
}//GEN-LAST:event_jButton2ActionPerformed

    private void diiKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_diiKeyTyped
        char c = evt.getKeyChar();
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_diiKeyTyped

    private void tiiKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tiiKeyTyped
         char c = evt.getKeyChar();
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_tiiKeyTyped

    private void didKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_didKeyTyped
          char c = evt.getKeyChar();
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_didKeyTyped

    private void tidKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tidKeyTyped
         char c = evt.getKeyChar();
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_tidKeyTyped

    private void ddiKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_ddiKeyTyped
          char c = evt.getKeyChar();
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_ddiKeyTyped

    private void tdiKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tdiKeyTyped
          char c = evt.getKeyChar();
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_tdiKeyTyped

    private void dddKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_dddKeyTyped
          char c = evt.getKeyChar();
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_dddKeyTyped

    private void tddKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tddKeyTyped
         char c = evt.getKeyChar();
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_tddKeyTyped

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new LlantasFurgon().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField ddd;
    private javax.swing.JTextField ddi;
    private javax.swing.JTextField did;
    private javax.swing.JTextField dii;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField tdd;
    private javax.swing.JTextField tdi;
    private javax.swing.JTextField tid;
    private javax.swing.JTextField tii;
    // End of variables declaration//GEN-END:variables

}
